package top.jacktgq.cas.unsafe;

import java.lang.reflect.Field;

import sun.misc.Unsafe;
/**
 * 
 * @Title: UnsafeAccessor.java 
 * @Package top.jacktgq.cas.unsafe 
 * @Description: 获取jdk自带的Unsafe类
 * @author CandyWall   
 * @date 2020年11月3日 下午9:22:30 
 * @version V1.0
 */
public class UnsafeAccessor {
	private static final Unsafe unsafe;
	static {
		Field theUnsafe;
		try {
			theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
			theUnsafe.setAccessible(true);
			unsafe = (Unsafe) theUnsafe.get(null);
		} catch (Exception e) {
			throw new Error(e);
		}
	}
	
	public static Unsafe getUnsafe() {
		return unsafe;
	}
}
